// Control the keyboard, joystick, etc...


#ifndef LIGHTY_CONTROLS_H 
#define LIGHTY_CONTROLS_H

#include <SDL.h>
#include "Lighty_Debug.h"

// Secondary keys can't be map.

const int Key_LeftSecond=SDLK_LEFT;
const int Key_DownSecond=SDLK_DOWN;
const int Key_UpSecond=SDLK_UP;
const int Key_RightSecond=SDLK_RIGHT;
const int Key_ConfirmSecond=SDLK_RETURN;
const int Key_BackSecond=SDLK_BACKSPACE;
int Key_Left=SDLK_q;
int Key_Down=SDLK_s;
int Key_Up=SDLK_z;
int Key_Right=SDLK_d;
int Key_Confirm=SDLK_a;
int Key_Back=SDLK_x;

// Use fucking switch statement, not if statement !

int Light_ReturnKey(int KeyError=1){ // Arg will be remove anyway.
	
  bool ReturnKeyQuit=false;
  SDL_Event ReturnKey;
  SDL_WaitEvent(&ReturnKey);
  Lighty_PrintDebug("Controls : Wait for an input to configure...");
  
  while(!ReturnKeyQuit){
  
    while(SDL_PollEvent(&ReturnKey)){
  
      if(ReturnKey.key.keysym.sym==SDLK_ESCAPE){

        Lighty_PrintDebug("Contrôle : Echap key detected.");
        ReturnKeyQuit=true;
	  
      }
      
      else{
		  
	    switch(ReturnKey.key.keysym.sym){ // Cherche si une touche protégée est en doublon.
		
		  case Key_LeftSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  case Key_UpSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  case Key_DownSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  case Key_RightSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  case Key_ConfirmSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  case Key_BackSecond:
		  
		    Lighty_PrintDebug("Key error : You can't map a secondary key !");
		    ReturnKeyQuit=true;
		    return KeyError;
		    break;
		    
		  default: 
		  
		    if(ReturnKey.key.keysym.sym==Key_Left){
				
			  Lighty_PrintDebug("Key error : Key not configured !");	
			  ReturnKeyQuit=true;
		      return KeyError;
				
		    }
		    
		    if(ReturnKey.key.keysym.sym==Key_Down){
				
			  Lighty_PrintDebug("Key error : Key not configured !");	
		      ReturnKeyQuit=true;
		      return KeyError;
				
			}
			
			if(ReturnKey.key.keysym.sym==Key_Up){
				
			  Lighty_PrintDebug("Key error : Key not configured !");
		      ReturnKeyQuit=true;
		      return KeyError;
				
			}
			
			if(ReturnKey.key.keysym.sym==Key_Right){
			
			  Lighty_PrintDebug("Key error : Key not configured !");
			  ReturnKeyQuit=true;
			  return KeyError;
				
			}
			
		    if(ReturnKey.key.keysym.sym==Key_Confirm){
				
			  Lighty_PrintDebug("Key error : Key not configured !");	
		      ReturnKeyQuit=true;
		      return KeyError;
				
			}
			
			if(ReturnKey.key.keysym.sym==Key_Back){
			  
			  Lighty_PrintDebug("Key error : Key not configured !");
		      ReturnKeyQuit=true;
		      return KeyError;
				
			}
				
			Lighty_PrintDebug("Controls : Key successfully map.");
		    ReturnKeyQuit=true;
		    return ReturnKey.key.keysym.sym;
              
	    }
  
      }
  
    }
  
  }
  
  return 0;
  
}

#endif
